﻿import com.dinmax.isolution.*
import com.dinmax.flash.utilities.math.ColorUtils;
import com.dinmax.flash.draw.utilities.ColorSelector;
import flash.display.*;
import flash.geom.ColorTransform;
import flash.geom.Transform;

class LightRGBEditorGUI
extends DeviceEditorGUI {
	
	private var device:LightRGB;
	private var listener:WindowDeviceGUI;
	
	function LightRGBEditorGUI(){
		super();
		var r:LightRGBEditorGUI = this;
		
		this["mcColorSelector"].onLoad = function(){
			this.listener = r;
			var o = r.getDevice().getValue();
			var val = ColorUtils.rgb2hex(o.r, o.g, o.b);
			this.setValue(val);
		}
		return;
	}
		
	public function getDevice():LightRGB{
		return this.device;
	}
	public function setDevice(newDevice:LightRGB):Void{
		super.setDevice(newDevice);
		return;
	}
		
	public function refresh():Void {
		super.refresh();
		
		var val:Object = this.device.getValue();
		var valHex:Number = ColorUtils.rgb2hex(val.r, val.g, val.b);
		if(valHex > 0) {
			this["mcState"].gotoAndStop(1);
			
		} else {
			this["mcState"].gotoAndStop(2);
			
		}
						
		return;
	}
	
	public function colorChange(nColor):Void {
		var o:Object = ColorUtils.hex2rgb(nColor);
		var sState:String = String(o.r)+","+String(o.g)+","+String(o.b);
		com.dinmax.isolution.HCC.setDeviceState(getDevice().getId(), sState);
		return;
	}
	
}